package com.bcu.calculus.controller;


import com.bcu.calculus.config.GlobalConfig;
import com.bcu.calculus.entity.*;

import com.bcu.calculus.service.SendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "02  事迹提交模块")
@RestController
@RequestMapping("/api/send")
public class SendController {

    @Resource
    private SendService sendService;

    @Resource
    private GlobalConfig globalConfig;

    @ApiOperation(value = "增加")
    @PostMapping(value = "/insert")
    public Message<?> insert(Send send){
        return sendService.insert(send);
    }


    @ApiOperation(value = "通过关键字删除")
    @DeleteMapping(value = "/deleteByPrimaryKey")
    public Message deleteByPrimaryKey(String sendId) {
        return sendService.deleteByPrimaryKey(sendId);
    }


    @ApiOperation(value = "通过主键修改")
    @PutMapping(value = "/updateByPrimaryKey")
    public Message updateByPrimaryKey(Send send){
        return sendService.updateByPrimaryKey(send);
    }


    @ApiOperation(value = "通过关键字查询")
    @GetMapping(value = "/selectByPrimaryKey")
    public Message<Send>selectByPrimaryKey(String sendId) {
        return sendService.selectByPrimaryKey(sendId);
    }


    @ApiOperation(value = "查询所有")
    @GetMapping(value = "/selectAllSend")
    public Message<List<Send>> selectAllSend(){
        return sendService.selectAllSend();
    }


    @ApiOperation(value = "根据用户id查和学期")
    @GetMapping(value = "/selectBySendUserId")
    public Message<List<Send>> selectBySendUserIdAndSemId(String sendUserId,Integer semId){
        return sendService.selectBySendUserIdAndSemId(sendUserId,semId);
    }

    @ApiOperation(value = "批量审核")
    @PostMapping(value = "/pushSend")
    public Message<?> pushSend(@RequestBody List<SendList2> sendList2){
        for (int i=0;i <sendList2.size(); i++){
            System.out.print(sendList2.size());
            SendList2 s =sendList2.get(i);
            System.out.print(s);
            sendService.pushSend(s);
        }
        return Message.success(null);
    }




    
//    @ApiOperation(value="上传图片")
//    @PostMapping(value="/Images" , headers = "content-type=multipart/form-data")
//    public String getImages(@RequestParam(value = "file") MultipartFile[] files, HttpServletRequest request) throws IOException {
//        return globalConfig.hostUrl+"bcucalculusImage/sendimage/"+ LoadUtil.upload(globalConfig.filePath+"sendimage/",files, request);
//    }


//    //测试mybatis用
//    @ApiOperation(value = "根据三个等级的路由编号查询send")
//    @GetMapping(value = "/getSendByManyList")
//    public Message<List<Send>> getSendByList(SendList sendList){
//        return sendService.getSendByManyList(sendList.getFlistId(),sendList.getSlistId(),sendList.getTlistId(),sendList.getSendSemseterId());
//    }
//
//    @ApiOperation(value = "根据一、二级路由编号查询send")
//    @GetMapping(value = "/getSendByTwoLists")
//    public Message<List<Send>> getSendByTwoList(String flist,String slist){
//        return sendService.getSendByTwoList(flist,slist);
//    }

    /*
    得重写，表改了
     */
//    @ApiOperation(value = "获取单个用户总分")
//    @GetMapping(value = "/getScoreByUserId")
//    public Message<Map<String,Float>>  getScoreByUserId(String userId){
//        return sendService.getScoreByUserId(userId);
//    }

/*
/*
    @ApiOperation(value = "获取每个人的平均分")
    @GetMapping(value = "/getAllAvScore")
    public Message<List<Send>> getAllAcScore(){
        return sendService.getAllAvScore();
    }

    @ApiOperation(value = "获取每个人的及格率")
    @GetMapping(value = "/getAllPR")
    public Message<List<Send>> getAllPR(){
        return sendService.getAllPR();
    }
*/

    /*
    得重写，表改了
     */

//    @ApiOperation(value = "查询党支部平均分")
//    @GetMapping(value = "/selectAllAvScore")
//    public Message<List<Send>> selectAllAvScore(){
//        return sendService.selectAllAvScore();
//    }
//
//
//    @ApiOperation(value = "查询党支部及格率")
//    @GetMapping(value = "/selectAllPR")
//    public Message<List<Send>> selectAllPR(){
//        return sendService.selectAllPR();
//    }


    @ApiOperation(value = "根据sendSemesterId返回当前学期全部活动信息")
    @GetMapping(value = "/getSendsBySemesterId")
    public Message<List<Send>> getSendsBySemesterId(Integer semesterId){
        return sendService.getsendsBySemesterId(semesterId);
    }

    @ApiOperation(value = "将send的分数设置为null")
    @GetMapping(value = "/setSendStatusAndSendScoreIsNull")
    public Message<?> setSendStatusAndSendScoreIsNull(String sendId,Integer sendStatus,String GiveUserId){
        return sendService.setSendStatusAndSendScoreIsNull(sendId,sendStatus,GiveUserId);
    }



}
